.class Lorg/microemu/midp/media/audio/PCToneRunnable;
.super Lorg/microemu/midp/media/audio/PCToneHelper;
.source "PCToneRunnable.java"

# interfaces
.implements Lorg/microemu/midp/media/RunnableInterface;


# instance fields
.field private running:Z


# direct methods
.method public constructor <init>(Ljavax/sound/sampled/SourceDataLine;Ljavax/sound/sampled/AudioInputStream;Ljavax/sound/sampled/AudioFormat;I)V
    .locals 0
    .parameter "sourceDataLine"
    .parameter "audioInputStream"
    .parameter "audioFormat"
    .parameter "size"

    .prologue
    .line 43
    invoke-direct {p0, p1, p2, p3, p4}, Lorg/microemu/midp/media/audio/PCToneHelper;-><init>(Ljavax/sound/sampled/SourceDataLine;Ljavax/sound/sampled/AudioInputStream;Ljavax/sound/sampled/AudioFormat;I)V

    .line 49
    return-void
.end method


# virtual methods
.method public close()V
    .locals 1

    .prologue
    .line 59
    invoke-virtual {p0}, Lorg/microemu/midp/media/audio/PCToneRunnable;->getSourceDataLine()Ljavax/sound/sampled/SourceDataLine;

    move-result-object v0

    invoke-interface {v0}, Ljavax/sound/sampled/SourceDataLine;->drain()V

    .line 60
    invoke-virtual {p0}, Lorg/microemu/midp/media/audio/PCToneRunnable;->getSourceDataLine()Ljavax/sound/sampled/SourceDataLine;

    move-result-object v0

    invoke-interface {v0}, Ljavax/sound/sampled/SourceDataLine;->stop()V

    .line 61
    invoke-virtual {p0}, Lorg/microemu/midp/media/audio/PCToneRunnable;->getSourceDataLine()Ljavax/sound/sampled/SourceDataLine;

    move-result-object v0

    invoke-interface {v0}, Ljavax/sound/sampled/SourceDataLine;->close()V

    .line 62
    return-void
.end method

.method public init()V
    .locals 2
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/lang/Exception;
        }
    .end annotation

    .prologue
    .line 53
    invoke-virtual {p0}, Lorg/microemu/midp/media/audio/PCToneRunnable;->getSourceDataLine()Ljavax/sound/sampled/SourceDataLine;

    move-result-object v0

    invoke-virtual {p0}, Lorg/microemu/midp/media/audio/PCToneRunnable;->getAudioFormat()Ljavax/sound/sampled/AudioFormat;

    move-result-object v1

    invoke-interface {v0, v1}, Ljavax/sound/sampled/SourceDataLine;->open(Ljavax/sound/sampled/AudioFormat;)V

    .line 54
    invoke-virtual {p0}, Lorg/microemu/midp/media/audio/PCToneRunnable;->getSourceDataLine()Ljavax/sound/sampled/SourceDataLine;

    move-result-object v0

    invoke-interface {v0}, Ljavax/sound/sampled/SourceDataLine;->start()V

    .line 55
    return-void
.end method

.method public declared-synchronized isRunning()Z
    .locals 1

    .prologue
    .line 68
    monitor-enter p0

    :try_start_0
    iget-boolean v0, p0, Lorg/microemu/midp/media/audio/PCToneRunnable;->running:Z
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    monitor-exit p0

    return v0

    :catchall_0
    move-exception v0

    monitor-exit p0

    throw v0
.end method

.method public run()V
    .locals 6

    .prologue
    .line 80
    const/4 v2, 0x1

    :try_start_0
    invoke-virtual {p0, v2}, Lorg/microemu/midp/media/audio/PCToneRunnable;->setRunning(Z)V

    .line 82
    invoke-virtual {p0}, Lorg/microemu/midp/media/audio/PCToneRunnable;->init()V

    .line 86
    :cond_0
    :goto_0
    invoke-virtual {p0}, Lorg/microemu/midp/media/audio/PCToneRunnable;->getAudioInputStream()Ljavax/sound/sampled/AudioInputStream;

    move-result-object v2

    iget-object v3, p0, Lorg/microemu/midp/media/audio/PCToneRunnable;->playBuffer:[B

    const/4 v4, 0x0

    iget-object v5, p0, Lorg/microemu/midp/media/audio/PCToneRunnable;->playBuffer:[B

    array-length v5, v5

    invoke-virtual {v2, v3, v4, v5}, Ljavax/sound/sampled/AudioInputStream;->read([BII)I

    move-result v0

    .local v0, cnt:I
    const/4 v2, -0x1

    if-eq v0, v2, :cond_1

    .line 88
    if-lez v0, :cond_0

    .line 90
    invoke-virtual {p0}, Lorg/microemu/midp/media/audio/PCToneRunnable;->getSourceDataLine()Ljavax/sound/sampled/SourceDataLine;

    move-result-object v2

    iget-object v3, p0, Lorg/microemu/midp/media/audio/PCToneRunnable;->playBuffer:[B

    const/4 v4, 0x0

    invoke-interface {v2, v3, v4, v0}, Ljavax/sound/sampled/SourceDataLine;->write([BII)I
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    goto :goto_0

    .line 98
    .end local v0           #cnt:I
    :catch_0
    move-exception v2

    move-object v1, v2

    .line 100
    .local v1, e:Ljava/lang/Exception;
    invoke-virtual {v1}, Ljava/lang/Exception;->printStackTrace()V

    .line 102
    .end local v1           #e:Ljava/lang/Exception;
    :goto_1
    return-void

    .line 94
    .restart local v0       #cnt:I
    :cond_1
    :try_start_1
    invoke-virtual {p0}, Lorg/microemu/midp/media/audio/PCToneRunnable;->close()V

    .line 96
    const/4 v2, 0x0

    invoke-virtual {p0, v2}, Lorg/microemu/midp/media/audio/PCToneRunnable;->setRunning(Z)V
    :try_end_1
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_0

    goto :goto_1
.end method

.method public declared-synchronized setRunning(Z)V
    .locals 1
    .parameter "running"

    .prologue
    .line 73
    monitor-enter p0

    :try_start_0
    iput-boolean p1, p0, Lorg/microemu/midp/media/audio/PCToneRunnable;->running:Z
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    .line 74
    monitor-exit p0

    return-void

    .line 73
    :catchall_0
    move-exception v0

    monitor-exit p0

    throw v0
.end method
